package util;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

public class DateAndLocalDate {

    public static Date localDateToDate(LocalDate localDate) {
        Date date = null;
        if (localDate != null) {
            ZonedDateTime atStartOfDay = localDate.atStartOfDay(ZoneId.systemDefault());
            date = Date.from(atStartOfDay.toInstant());
        }
        return date;
    }

    public static LocalDate dateToLocalDate(Date date) {
        if (date != null) {
            Instant instant = date.toInstant();
            ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefault());
            return zonedDateTime.toLocalDate();
        }
        return null;
    }
}
